package com.wuyan.example.consumer;

import com.wuyan.example.common.model.User;
import com.wuyan.example.common.service.UserService;
import com.wuyan.wurpc.bootstrap.ConsumerBootstrap;
import com.wuyan.wurpc.config.RpcConfig;
import com.wuyan.wurpc.proxy.ServiceProxyFactory;
import com.wuyan.wurpc.utils.ConfigUtils;

/**
 * 简易服务消费者示例
 */
public class ConsumerExample {

    public static void main(String[] args) {
        //服务提供者初始化
        ConsumerBootstrap.init();
        long startTime = System.currentTimeMillis(); // 或者使用 currentTimeMillis()

        //获取代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("wuyan");

        //调用
        User newUser = userService.getUser(user);
        long endTime = System.currentTimeMillis();  // 或者使用 currentTimeMillis()
        long duration = endTime - startTime;
        System.out.println("使用TCP所需时间：" + duration + "ms");
        if(newUser != null) {
            System.out.println(newUser.getName());
        }else{
            System.out.println("user == null");
        }
        long number = userService.getNumber();
        System.out.println(number);
    }

}
